import {Entity, PrimaryGeneratedColumn, Column, Timestamp, OneToMany} from 'typeorm'
import {PartEntity} from '../part/part.entity'


@Entity({name: 'books'})
export class BookEntity {
    @PrimaryGeneratedColumn({comment: '主键id'})
    id: number;

    @Column({length: 20, comment: '书名'})
    bookName: string;

    @Column({comment: '封面'})
    imgPath: string;

    @Column({comment: '是否置顶'})
    isStick: string;

    @Column({comment: '摘要'})
    summary: string;

    @Column({comment: '同读人数'})
    readCount: number;

    @OneToMany((type) => PartEntity, (part) => part.book)
    parts: PartEntity[]

    @Column({type: 'timestamp', default: () => 'current_timestamp'})
    bookTime: Timestamp;

    @Column({type: 'timestamp', default: () => 'current_timestamp'})
    createTime: Timestamp;

    @Column({type: 'timestamp', onUpdate: 'current_timestamp', default: () => 'current_timestamp'})
    updateTime: Timestamp;
}